<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@page import="com.zaofan.bean.Admin" %>
<%@page import="com.zaofan.bean.AdminType" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
 String contextPath = request.getContextPath();
 Admin admin = (Admin) session.getAttribute("admin");
 if (admin == null) {
  response.sendRedirect(contextPath + "/login.jsp?state=" + "session-invalid");
  return;
 }
 if (admin.getType() != AdminType.admin.ordinal() && admin.getType() != 4) {
  response.sendRedirect(contextPath + "/login.jsp?state=" + "session-invalid");
  return;
 }
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <title>创建酒店</title>
 <link href="<%=contextPath%>/admin/css/base.css" rel="stylesheet"/>
 <link href="<%=contextPath%>/admin/assets/css/bootstrap.min.css"
       rel="stylesheet"/>
 <link rel="stylesheet"
       href="<%=contextPath%>/admin/assets/css/font-awesome.min.css"/>
 <!--[if IE 7]>
 <link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/font-awesome-ie7.min.css"/>
 <![endif]-->
 <link rel="stylesheet"
       href="<%=contextPath%>/admin/assets/css/ace.min.css"/>
 <link rel="stylesheet"
       href="<%=contextPath%>/admin/assets/css/ace-rtl.min.css"/>
 <link rel="stylesheet"
       href="<%=contextPath%>/admin/assets/css/ace-skins.min.css"/>
 <!--[if lte IE 8]>
 <link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-ie.min.css"/>
 <![endif]-->
 <script src="<%=contextPath%>/admin/assets/js/ace-extra.min.js"></script>
 <!--[if lt IE 9]>
 <script src="<%=contextPath%>/admin/assets/js/html5shiv.js"></script>
 <script src="<%=contextPath%>/admin/assets/js/respond.min.js"></script>
 <![endif]-->
 <link rel="stylesheet"
       href="<%=contextPath%>/admin/assets/css/jquery-ui-1.10.3.custom.min.css"/>
 <link rel="stylesheet"
       href="<%=contextPath%>/admin/assets/css/chosen.css"/>
 <script type="text/javascript">
  var contextPath = '<%=contextPath%>';
 </script>
</head>
<body style="background-color: #fff;">
<div class="breadcrumbs" id="breadcrumbs">
 <script type="text/javascript">
  try {
   ace.settings.check('breadcrumbs', 'fixed')
  } catch (e) {
  }
 </script>
 <ul class="breadcrumb" style="padding: 20px; color: #3a87ad;">
 </ul>
</div>

<div class="container">

 地址列表
 <label class="sr-only" for="openbuilder">Email address</label>
<select id="openarea" onchange="getBuilder()">
  <option data-buidlerId="0">请选择开通区域</option>
</select>
 区域列表
 <select id="openbuilder">

 </select>
 <input id="hotelNo" type="text" placeholder="输入酒店编号(自定义数字英文搭配)"/>
 <button type="button" class="btn btn-success" id="createbtn">生成酒店</button>
 <button type="button" class="btn btn-success" id="querybtn">查询酒店二维码</button>
 <div id="qrcode"></div>


</div>





<div id="loading"
     style="width: 32px; height: 32px; position: fixed; left: 40%; top: 40%; display: none;">
 <img src="<%=contextPath%>/admin/assets/css/images/loading.gif"
      width="32" height="32"/>
</div>
<div class="popover"
     style="z-index: 9999; width: 150px; position: fixed; left: 40%; top: 40%;">
 <div class="arrow"></div>
 <div class="popover-inner">
  <h3 class="popover-title">操作提示</h3>
  <div class="popover-content" id="popover-content">
   <p>操作成功</p>
  </div>
 </div>
</div>

<script type="text/javascript">
 if ("ontouchend" in document)
  document
          .write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>" + "<" + "/script>");
</script>
<script type="text/javascript">
 window.jQuery
 || document
         .write("<script src='<%=contextPath%>/admin/assets/js/jquery-2.0.3.min.js'>"
                 + "<" + "script>");
</script>

<!--[if IE]>
<script type="text/javascript">
 window.jQuery || document.write("<script src='<%=contextPath%>/admin/assets/js/jquery-1.10.2.min.js'>" + "<" + "script>");
</script>
<![endif]-->
<script type="text/javascript">
 if ("ontouchend" in document)
  document
          .write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
                  + "<" + "script>");
</script>
<script src="<%=contextPath%>/admin/assets/js/bootstrap.min.js"></script>
<script src="<%=contextPath%>/admin/assets/js/typeahead-bs2.min.js"></script>
<script type="text/javascript" src="http://cdn.staticfile.org/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>

<!--[if lte IE 8]>
<script src="assets/js/excanvas.min.js"></script>
<![endif]-->
<script
        src="<%=contextPath%>/admin/assets/js/jquery-ui-1.10.3.custom.min.js"></script>
<script
        src="<%=contextPath%>/admin/assets/js/jquery.ui.touch-punch.min.js"></script>
<script src="<%=contextPath%>/admin/assets/js/jquery.slimscroll.min.js"></script>
<script
        src="<%=contextPath%>/admin/assets/js/jquery.easy-pie-chart.min.js"></script>
<script src="<%=contextPath%>/admin/assets/js/jquery.sparkline.min.js"></script>
<script src="<%=contextPath%>/admin/assets/js/ace-elements.min.js"></script>
<script src="<%=contextPath%>/admin/assets/js/ace.min.js"></script>
<script src="<%=contextPath%>/admin/js/common.js"></script>
<script src="<%=contextPath%>/admin/assets/js/jquery-form.js"></script>
<script
        src="<%=contextPath%>/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
<script
        src="<%=contextPath%>/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
<script
        src="<%=contextPath%>/admin/assets/js/date-time/bootstrap-datepicker.min.js"></script>





<script type="text/javascript">
   init();
   function init(){
      //读取开通酒店加入select

     $.ajax({
       url:"/area",
       type:"get",
       data:{
        action:"open",
        cityId:"<%=admin.getCityId()==0?"":admin.getCityId()%>"
       },
      success:function(result){
        var result = JSON.parse(result);
       var data = result.data;
       for (var i in data){
        var html = '<option data-areaId='+data[i].id+'>'+data[i].areaName+'</option>'
        var $html = $(html);
        $("#openarea").append($html);
       }
      }
     })
   }

   function getBuilder(){
   var areaId = $("#openarea option:selected").attr("data-areaId");
    $.ajax({
     url:"/builder",
     type:"get",
     data:{
      action:"open",
      cityId:"<%=admin.getCityId()==0?"":admin.getCityId()%>",
      areaId:areaId,
     },
     success:function(result){
      var result = JSON.parse(result);
      var data = result.data;
      $("#openbuilder").html("");
      for (var i in data){
       var html = '<option data-builderId='+data[i].id+'>'+data[i].builderName+'</option>'
       var $html = $(html);
       $("#openbuilder").append($html);
      }
     }
    })
   }
   $("#querybtn").click(function(){
    var hotelNo = $("#hotelNo").val();
    if (hotelNo ==null ){
     alert("请先输入酒店编号");
     return ;
    }
    var url = "http://m.52letsgo.cn/hotel.do?hotelNo="+hotelNo;
//    var url = "http://beta.52letsgo.cn/home/beforelogin/hotel_entry.do?hotelNo="+hotelNo;
    //生成二维码
    $('#qrcode').html("");
    $('#qrcode').qrcode(url);
   })

   $("#createbtn").click(function () {
    var builderId = $("#openbuilder option:selected").attr("data-builderId")
    var hotelNo = $("#hotelNo").val();

    if (builderId==null || hotelNo ==null || hotelNo == ''){
      alert("不完善的地址信息");
     return ;
    }




   $("#loading").show();
    $("#createbtn").prop("disabled",true);
    $.ajax({
             type: "GET",
             url: "/mobile/user/address",
             data: {action:"createHotel",builderId:builderId,hotelNo:hotelNo},
             dataType: "json",
             success: function(data) {
              $("#createbtn").prop("disabled",false);
              $("#loading").hide();
               showMessage(data.msg)
              if(data.success){
               var hotelNo = data.data;
               var url = "http://m.52letsgo.cn/hotel.do?hotelNo="+hotelNo;
//               var url = "http://beta.52letsgo.cn/home/beforelogin/hotel_entry.do?hotelNo="+hotelNo;
                //生成二维码
               $('#qrcode').html("");
               $('#qrcode').qrcode(url);
              }


             },



              error: function (msg) {
               $("#loading").hide();
               showMessage("操作失败");
               $("#createbtn").prop("disabled",false);

              }
            }
    );

   })


</script>
</body>
</html>